<?php

class HTMLUtil
{
//	private $matrixarray;
	
	public static function WriteActionButton($name,$action){
		$matrixarray = $_SESSION['accessmatrix'];
		$task = empty($_REQUEST['task'])?"default":$_REQUEST['task'];
		$gid = $_SESSION['user']->getGid();
		$key = substr($action,0,strpos($action, "("));
		try {
			$mlevel = $matrixarray[$task][$key];
			if($gid <= $mlevel){
				echo "<a href=\"javascript:$action;\" class=\"ui-state-default ui-corner-all\">$name</a>";
			}
//			echo "[$gid,$task,$name,$action,$mlevel]";
		} catch (Exception $e) {
			echo "[$gid,$task,$name,$action]";
		    echo '[' .$e->getMessage(), "]";
		}
	}
	public static function WriteButton($name,$id){
		$matrixarray = $_SESSION['accessmatrix'];
		$task = empty($_REQUEST['task'])?"default":$_REQUEST['task'];
		$gid = $_SESSION['user']->getGid();
		$mlevel = $matrixarray[$task][$id];
		if($gid <= $mlevel){
			echo "<a href=\"javascript: void(0)\" id=\"$id\" class=\"ui-state-default ui-corner-all\">$name</a>";
		}
//		echo "[$gid,$task,$id,$mlevel]";
	}
	public static function WriteIdButton($name,$id){
		$matrixarray = $_SESSION['accessmatrix'];
		$task = empty($_REQUEST['task'])?"default":$_REQUEST['task'];
		$gid = $_SESSION['user']->getGid();
		$mlevel = $matrixarray[$task][$id];
		if($gid <= $mlevel){
			echo "<a href=\"javascript:void(0)\" id=\"$id\" class=\"ui-state-default ui-corner-all\">$name</a>";
		}
//		echo "[$gid,$task,$id,$mlevel]";
	}
	public static function EditButton($id){
		self::WriteButton("Edit",$id);
	}
	public static function AddButton($id){
		self::WriteButton("Add",$id);
	}
	public static function ViewButton($id){
		self::WriteButton("View",$id);
	}
	public static function DeleteButton($id){
		self::WriteButton("Delete",$id);
	}

	public static function WeekdayWord($d){
		switch ($d){
			case 1:
				echo "Monday";
				break;
			case 2:
				echo "Tuesday";
				break;
			case 3:
				echo "Wednesday";
				break;
			case 4:
				echo "Thursday";
				break;
			case 5:
				echo "Friday";
				break;
			case 6:
				echo "Saturday";
				break;
			case 7:
				echo "Sunday";
				break;
			
		}
	}
}

?>